package gui;

import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.*;
import rpgsdb.db.RPGSDBWrapper;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Segl0 extends JFrame{
    public static RPGSDBWrapper db;
    private Segl1 segL1;
    public Segl0(){
        super("Segminator II");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(1280, 800);
        this.setResizable(true);
        this.addComponentListener(new ComponentAdapter() {
            public void componentResized(ComponentEvent e) {
                refreshContainer();
            }
        });
        connectToDatabase();
        segL1 = new Segl1(this);
        segL1.setOpaque(true);
        this.getContentPane().add(segL1);
        this.setJMenuBar(new Menu(segL1));
        this.setContentPane(segL1);
        this.setVisible(true);
        this.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent e){disconnectToDatabase();}
        });
    }
    public static void connectToDatabase(){db = new RPGSDBWrapper(false);db.connect();}
    public static void disconnectToDatabase(){db.disconnect();}
    public void refreshContainer(){segL1.updateAllCardsOnFrameResize();this.repaint();this.validate();}
}